﻿<%@ Page Title="baseinfo" Language="C#" MasterPageFile="~/EasyUI.master" AutoEventWireup="true" CodeBehind="List.aspx.cs" Inherits="jnlamp.Web.baseinfo.List" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="../Script/datetime.js"></script>
    <script type="text/javascript">
        var sprovince = "";
        var scity = "";
        var scounty = "";
        var se=""; //镇
        var sebm="";//镇的编码        
        var loc="";//选择点的地址        
        var label;
        $.extend($.fn.tree.methods, {
            getLevel: function (jq, target) {
                var l = $(target).parentsUntil("ul.tree", "ul");
                return l.length + 1;
            }
        });
        $(function () {
            InitGird();
            InitSearch();
            InitTree();
            InitPro();
        });
        function InitTree() {
            $('#pt').tree({
                width: '100%', //宽度                
                lines: true,
                //data: provincetree,   
                url: '../areainfo/GetArea.ashx', //请求数据的页面 
                method: 'post',
                queryParams: { "action": "querymyareauser" },
                onBeforeExpand: function (node) {
                    $("#pt").tree("options").queryParams = { "action": "queryyb" };
                    $('#pt').tree('options').url = "../areainfo/GetArea.ashx?pid=" + node.id;
                },
                onClick: function (node) {
                    sprovince = scity = scounty = se = "";
                    if (node.text != "") {
                        var lv = $('#pt').tree("getLevel", node.target);
                        if (lv == 2) {
                            sprovince = node.text;
                        }
                        else if (lv == 3) {
                            scity = node.text;
                            sprovince = $('#pt').tree("getParent", node.target).text;
                        }
                        else if (lv == 4) {
                            scounty = node.text;
                            var node1 = $('#pt').tree("getParent", node.target)
                            scity = node1.text;
                            sprovince = $('#pt').tree("getParent", node1.target).text;
                        }
                        else if (lv == 5) {

                            var node1 = $('#pt').tree("getParent", node.target);
                            scounty = node1.text;
                            var node2 = $('#pt').tree("getParent", node1.target);
                            scity = node2.text;
                            sprovince = $('#pt').tree("getParent", node2.target).text;
                            se = node.text;

                        }
                        sebm = node.bm;
                        reloadgrid();
                    }
                },
                onLoadSuccess: function (node, param) {
                    //reloadgrid();
                }
            });

        }

        function InitGird() {
            $('#tt').datagrid({
                title: '基地列表', //表格标题
                url: 'GetBase.ashx', //请求数据的页面
                sortName: 'basedate', //排序字段
                idField: 'bid', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度
                //height: $(parent.document).find("#mainPanle").height() - 35 > 0 ? $(parent.document).find("#mainPanle").height() - 35 : 500, //高度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                singleSelect: true,
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                method: 'post',
                columns: [[
                    { field: 'ckb', checkbox: true },
                    { title: '基地名称', field: 'basename', width: 150 },
                    {
                        title: '创建日期', field: 'basedate', width: 150, formatter: function (value, row, index) {
                            if (value != "") {

                                if (value.indexOf("-") != -1)
                                    value = value.replace(/-/g, "/");
                                return new Date(value).pattern("yyyy年M月d日");
                            }
                        }
                    },
                    { title: '备注', field: 'basemark', width: 150 },
                    { title: '项目名称', field: 'proname', width: 100 },
                    { title: '地址', field: 'address', width: 150 },
                    {
                        title: '网关设置', field: 'a', width: 100, formatter: function (value, row, index) {
                            var city=row.pname+row.cname+row.coname;
                            city=encodeURI(encodeURI(city));
                            return '<a href="#" onclick="top.addTab(\'' + row.basename + '\',\'/gatewayinfo/list.aspx?bid=' + row.bid + '&city='+city+'\', \'icon icon-magic\');">网关数据</a>';

                        }
                    }

                ]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "query" },
                pagination: true, //是否开启分页
                pageList: [10, 20, 30, 40, 50],
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true //行号
            });
        }

        function getQueryParams(queryParams) {
            if (sebm != "")
                queryParams.sebm = sebm;
            return queryParams;

        }
        //增加查询参数，重新加载表格  
        function reloadgrid() {

            //查询参数直接添加在queryParams中      
            var queryParams = $('#tt').datagrid('options').queryParams;
            getQueryParams(queryParams);
            $('#tt').datagrid('options').queryParams = queryParams;
            $("#tt").datagrid('reload');

        }
        //初始化搜索框
        function InitSearch() {
            $("#ipt_search").searchbox({
                width: 100,
                //iconCls: 'icon-save',
                searcher: function (val, name) {
                    $('#tt').datagrid('options').queryParams.search_type = name;
                    $('#tt').datagrid('options').queryParams.search_value = val;
                    $('#tt').datagrid('reload');
                },
                prompt: '请输入查询信息'
            });            
        }

        function InitPro() {
            $('#pid').combobox({
                url: '../projectinfo/GetProject.ashx?action=ddllist',
                valueField: 'pid',
                textField: 'proname',
                panelHeight: 'auto',
                editable: false,
                onLoadSuccess: function () {
                    var data = $('#pid').combobox('getData');
                    if (data.length > 0)
                        $("#pid").combobox('select', data[0].pid);
                }
            });           

        }
        function newUser() {            
            if (se == "") {
                $.messager.alert("提示", "请选择乡镇！", "info");
                return;
            }
            //清空内容  
            $('#fm').form('clear');            
            $('#abh').val(sebm);
            $('#myloc').text(se);
            $('#dlg').dialog('open').dialog('setTitle', '添加基地');
            document.getElementById("test").value = "add";
        }

        function editUser() {

            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要修改的行！", "info");
            }
            if (row) {
                $('#dlg').dialog('open').dialog('setTitle', '修改类别');
                document.getElementById("test").value = "modify";
                $('#fm').form('load', row);
                
            }
        }
        //添加        
        function saveUser() {
            var test = document.getElementById("test").value;
            var f = $('#fm');
            if (test == "add") {
                f.form('submit', {
                    url: "GetBase.ashx?action=" + test,
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (result) {
                        if (result.indexOf("T") == 0) {
                            $('#dlg').dialog('close');
                            $.messager.alert("提示", "恭喜您，信息添加成功", "info");
                            $('#tt').datagrid('reload');
                        }
                        else if ((result.indexOf("F") == 0)) {
                            $.messager.alert("提示", "添加失败，请重新操作！", "info");
                            return;
                        }
                        else if ((result.indexOf("L") == 0)) {
                            $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                            top.location = '/index.aspx';
                            return;
                        }
                    }
                });

            } else {

                $('#fm').form('submit', {
                    url: "GetBase.ashx?action=" + test,
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (result) {
                        if (result.indexOf("T") == 0) {
                            $('#dlg').dialog('close');
                            $('#tt').datagrid('clearSelections');
                            $.messager.alert("提示", "恭喜您，信息修改成功", "info");
                            $('#tt').datagrid('reload');

                        }
                        else if ((result.indexOf("F") == 0)) {
                            $.messager.alert("提示", "添加失败，请重新操作！", "info");
                            return;
                        }
                        else if ((result.indexOf("L") == 0)) {
                            $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                            top.location = '/index.aspx';
                            return;
                        }
                    }
                });
            }
        }

        function removeUser() {
            var test = document.getElementById("test").value = "delete";
            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要删除的行！", "info");
            }
            if (row) {
                $.messager.confirm('提示', '你确定要删除这条信息吗？', function (r) {
                    if (r) {
                        $('#fm').form('submit', {
                            url: 'GetBase.ashx?bid=' + row.bid + "&action=" + test,
                            onSubmit: function () {
                                //return $(this).form('validate');  
                            },
                            success: function (result) {
                                if (result.indexOf("T") == 0) {
                                    $('#dlg').dialog('close');
                                    $('#tt').datagrid('clearSelections'); //清空选中的行  
                                    $.messager.alert("提示", "恭喜您，信息删除成功！", "info");
                                    $('#tt').datagrid('reload');
                                }
                                else if ((result.indexOf("F") == 0)) {
                                    $.messager.alert("提示", "删除失败，请删除基地下网关后再操作！", "info");
                                    return;
                                }
                                else if ((result.indexOf("L") == 0)) {
                                    $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                                    top.location = '/index.aspx';
                                    return;
                                }
                            }
                        });
                    }
                })
            }
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="easyui-layout" style="width: 100%; height: 100%;">
        <div region="west" id="west" split="true" title="区域检索" style="width: 180px; overflow: scroll">
            <ul id="pt"></ul>
        </div>
        <div region="center" style="background: #eee; overflow: auto">
            <table id="tt">
            </table>
            <div id="tab_toolbar" style="padding: 4px;">
                <table cellpadding="0" cellspacing="0" style="width: 100%">
                    <tr>
                        <td style="padding-left: 2px">
                            <a href="#" onclick="newUser();" id="a_add"
                                class="easyui-linkbutton" iconcls="icon-add">添加</a>
                            <a href="javascript:void(0)" onclick="editUser() " class="easyui-linkbutton" data-options="iconCls:'icon-edit'">修改</a>
                            <a href="#" onclick="removeUser();return false;" id="a_del" class="easyui-linkbutton" iconcls="icon-cancel">删除</a>

                        </td>
                        <td style="text-align: right; padding-right: 15px">
                            <input id="ipt_search" menu="#search_menu" />
                            <div id="search_menu" style="width: 220px">
                                <div name="usernum">
                                    名称
                                </div>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
            <div id="dlg" class="easyui-dialog" style="width: 400px; height: auto; padding: 10px 20px"
                data-options="closed:true,buttons:'#dlg-buttons',shadow:false">
                <form id="fm" method="post" enctype="multipart/form-data">
                    <div class="fitem">
                                <label>地区：</label>
                                <span id="myloc"></span>
                            </div>
                    <div class="fitem">
                    <label>项目：</label>
                    <input id="pid" name="pid" style="width: 150px;" />

                </div>
                    <div class="fitem">
                        <label>基地名称：</label>
                        <input name="basename" id="basename" required="true" />
                        <input name="test" id="test" type="hidden" />
                        <input name="bid" id="bid" type="hidden" />
                        <input name="abh" id="abh" type="hidden" />
                    </div>
                    <div class="fitem">
                        <label>创建日期：</label>
                        <input id="basedate" name="basedate" class="easyui-datetimebox" data-options="required:true" />
                    </div>
                    <div class="fitem">
                        <label>基地备注：</label>
                        <textarea id="basemark" name="basemark">  </textarea>
                    </div>
                </form>
            </div>
            <div id="dlg-buttons">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveUser()">保存</a>
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlg').dialog('close')">关闭</a>
            </div>
        </div>
    </div>
</asp:Content>
